package ca.swank.hq.hard;

import ca.swank.hardquor.*;

import java.util.LinkedList;
import java.util.TreeSet;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Properties;
import java.io.*;
import java.util.StringTokenizer;


/**
* manages a skin file
*
* @author Jesse Wilson
* @version 1.0 10/18/2001
*/
public abstract class HardquorSkin
{
  // the name of the skin properties file, in the root of the zip file
  public static final String SKIN_PROPERTIES = "hardquorskin.properties";

  // window information
  public int PANEL_HEIGHT;
  public int PANEL_WIDTH;
  public String PANEL_TITLE;

  // hot spots for clicking the board
  public int[][] HOT_SPOT_ROWS;
  public int[][] HOT_SPOT_COLS;

  // where to render the players
  public int[] PLAYER_LOC_ROWS;
  public int[] PLAYER_LOC_COLS;

  // where to render the walls
  public int[] WALL_VERTICAL_Y; // = new int[] { 183, 165, 148, 131, 112, 95, 77, 60, 42, 24 };
  public int[] WALL_VERTICAL_X; // = new int[] { 24, 41, 59, 76, 94, 112, 129, 147 };
  public int[] WALL_HORIZONTAL_Y; // = new int[] { 198, 181, 163, 145, 128, 110, 93, 75, 57, 40 };
  public int[] WALL_HORIZONTAL_X; // = { 8, 26, 43, 61, 79, 96, 114, 132, 149 };
  public int WALL_HORIZONTAL_WIDTH; // = 33;
  public int WALL_HORIZONTAL_HEIGHT; // = 3;
  public int WALL_VERTICAL_WIDTH; // = 3;
  public int WALL_VERTICAL_HEIGHT; // = 33;
  public int HOT_SPOT_WALL_PADDING; // = 2;

  // where to render wall count
  public int COUNT_PLAYER_ONE_X;
  public int COUNT_PLAYER_ONE_Y;
  public int COUNT_PLAYER_TWO_X;
  public int COUNT_PLAYER_TWO_Y;

  // images
  public Image IMAGE_BOARD;
  public Image IMAGE_PLAYER_ONE;
  public Image IMAGE_PLAYER_TWO;
  public Image IMAGE_PLAYER_ONE_SHADOW;
  public Image IMAGE_PLAYER_TWO_SHADOW;
  public Image IMAGE_LEGAL_WALK;
  public Image[] IMAGE_COUNT;

  // colours
  public Color COLOUR_WALL; // = new Color(0,0,0);
  public Color COLOUR_SHADOW_WALL_LEGAL; // = new Color(0,153,0);
  public Color COLOUR_SHADOW_WALL_ILLEGAL; // = new Color(255,0,0);


  /**
   * constructor for child classes; such classes should call the
   * loadSkinAttributes() and loadSkinImages() methods.
   */
  protected HardquorSkin()
  {
  }

  /**
   * loads primitive values into skin from properties map
   */
  protected void loadSkinAttributes()
  {
    // window information
    PANEL_HEIGHT = getInt("PANEL_HEIGHT");
    PANEL_WIDTH = getInt("PANEL_WIDTH");
    PANEL_TITLE = getString("PANEL_TITLE");

    // hot spots for clicking the board
    HOT_SPOT_ROWS = new int[][] { getIntArray("HOT_SPOT_ROWS_START"),
                                  getIntArray("HOT_SPOT_ROWS_FINISH") };
    HOT_SPOT_COLS = new int[][] { getIntArray("HOT_SPOT_COLS_START"),
                                  getIntArray("HOT_SPOT_COLS_FINISH") };

    // where to render players
    PLAYER_LOC_ROWS = getIntArray("PLAYER_LOC_ROWS"); //new int[] { 199, 181, 164, 146, 128, 111, 93, 75, 58, 40, 21 };
    PLAYER_LOC_COLS = getIntArray("PLAYER_LOC_COLS"); //new int[] { 6, 24, 42, 59, 77, 94, 112, 130, 147 };

    // where to render the walls
    WALL_VERTICAL_Y = getIntArray("WALL_VERTICAL_Y");
    WALL_VERTICAL_X = getIntArray("WALL_VERTICAL_X");
    WALL_HORIZONTAL_Y = getIntArray("WALL_HORIZONTAL_Y");
    WALL_HORIZONTAL_X =  getIntArray("WALL_HORIZONTAL_X");
    WALL_HORIZONTAL_WIDTH = getInt("WALL_HORIZONTAL_WIDTH");
    WALL_HORIZONTAL_HEIGHT = getInt("WALL_HORIZONTAL_HEIGHT");
    WALL_VERTICAL_WIDTH = getInt("WALL_VERTICAL_WIDTH");
    WALL_VERTICAL_HEIGHT = getInt("WALL_VERTICAL_HEIGHT");
    HOT_SPOT_WALL_PADDING = getInt("HOT_SPOT_WALL_PADDING");

    // where to render wall count
    COUNT_PLAYER_ONE_X = getInt("COUNT_PLAYER_ONE_X");;
    COUNT_PLAYER_ONE_Y = getInt("COUNT_PLAYER_ONE_Y");;
    COUNT_PLAYER_TWO_X = getInt("COUNT_PLAYER_TWO_X");;
    COUNT_PLAYER_TWO_Y = getInt("COUNT_PLAYER_TWO_Y");;

    // colours
    COLOUR_WALL = getColor("COLOUR_WALL"); //new Color(0,0,0);
    COLOUR_SHADOW_WALL_LEGAL = getColor("COLOUR_SHADOW_WALL_LEGAL"); //new Color(0,153,0);
    COLOUR_SHADOW_WALL_ILLEGAL = getColor("COLOUR_SHADOW_WALL_ILLEGAL"); //new Color(255,0,0);
  }

  /**
   * loads images into skin via names in properties map, relative to the
   * directory that skinFile is in.
   */
  protected void loadSkinImages()
  { // images
    IMAGE_BOARD = getImage("IMAGE_BOARD"); // (resources/hard/board.png");
    IMAGE_PLAYER_ONE = getImage("IMAGE_PLAYER_ONE"); // ("resources/hard/player_one.png");
    IMAGE_PLAYER_TWO = getImage("IMAGE_PLAYER_TWO"); // ("resources/hard/player_two.png");
    IMAGE_PLAYER_ONE_SHADOW = getImage("IMAGE_PLAYER_ONE_SHADOW"); // ("resources/hard/player_one_shadow.png");
    IMAGE_PLAYER_TWO_SHADOW = getImage("IMAGE_PLAYER_TWO_SHADOW"); // ("resources/hard/player_two_shadow.png");
    IMAGE_LEGAL_WALK = getImage("IMAGE_LEGAL_WALK"); // ("resources/hard/move_shadow.png");
    IMAGE_COUNT = new Image[11];
    IMAGE_COUNT[0] = getImage("IMAGE_COUNT_00"); // ("resources/hard/count_0.png");
    IMAGE_COUNT[1] = getImage("IMAGE_COUNT_01"); // ("resources/hard/count_1.png");
    IMAGE_COUNT[2] = getImage("IMAGE_COUNT_02"); // ("resources/hard/count_2.png");
    IMAGE_COUNT[3] = getImage("IMAGE_COUNT_03"); // ("resources/hard/count_3.png");
    IMAGE_COUNT[4] = getImage("IMAGE_COUNT_04"); // ("resources/hard/count_4.png");
    IMAGE_COUNT[5] = getImage("IMAGE_COUNT_05"); // ("resources/hard/count_5.png");
    IMAGE_COUNT[6] = getImage("IMAGE_COUNT_06"); // ("resources/hard/count_6.png");
    IMAGE_COUNT[7] = getImage("IMAGE_COUNT_07"); // ("resources/hard/count_7.png");
    IMAGE_COUNT[8] = getImage("IMAGE_COUNT_08"); // ("resources/hard/count_8.png");
    IMAGE_COUNT[9] = getImage("IMAGE_COUNT_09"); // ("resources/hard/count_9.png");
    IMAGE_COUNT[10] = getImage("IMAGE_COUNT_10"); // ("resources/hard/count_10.png");
  }



  /**
   * gets the image of the specified name
   */
  protected abstract Image getImage(String key);

  /**
   * gets the integer of the specified name
   */
  protected abstract int getInt(String key);

  /**
   * gets the integer array of the specified name
   */
  protected abstract int[] getIntArray(String key);

  /**
   * gets the String of the specified name
   */
  protected abstract String getString(String key);

  /**
   * Given a html-like color such as #bbac33, turns it
   * into a java.awt.Color. The # on the front is optional.
   */
  protected abstract Color getColor(String key);

}